/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : name_auth.js                                 
*  Description  : 실명인증 완료
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-08-17  김효순    Created.  
*******************************************************************************/

jQuery(function($){
	
	
	function clsComm()
	{
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){

		}
		// 인증요청결과
		, getNameAuth: function(arg){
			arg = arg || {};
			arg["콜백"] = arg["콜백"] || function(){};
			
			//ajax
			var serviceName = "getNcResult";
			var options = {
				"encData": arg["암호화코드"]
			}
			_gf.ajax({
				"sid": "US001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "결과값": {}
				}
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					var obj = items;
					res["결과값"] = {
						"응답코드": _util.nvl(obj["ncResult"])
						, "메시지": _util.nvl(obj["message"])
						, "이름": _util.nvl(obj["ncName"])
					}
				}
				
				arg["콜백"].apply(null, [res]);
			});
		}
	}
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		
		this._permitStart = null;
	}
	
	clsControl.prototype = {
		_init: function(){
			this._preload();
			
			this.objComm = new clsComm();
			
			this._beforeStart();
			this._bind();
		}
		, _preload: function(){
			if(opener){
				if(opener.document.objControl){
					this.openerControl = opener.document.objControl;
				}
			}
			
//			if(!this.openerControl){
//				self.close();
//				return;
//			}
		}
		, _beforeStart: function(){
			var thisClass = this;
			this._permitStart = {
				
			}
			
			_util.executeThread(function(){
				for(var k in thisClass._permitStart){
					if(!thisClass._permitStart[k]) return false;
				}
				
				return true;
			}, function(){
				_gf.spinEnd();
				thisClass._start();
			});
		}
		, _bind: function(){
			var thisClass = this;
			
			
		}
		, _start: function(){
			var thisClass = this;
			
			//document.charset = "euc-kr";
			
			//결과요청
			this.objComm.getNameAuth({
				"암호화코드": _enc_data
				, "콜백": function(ret){
					thisClass.finishNameAuth(ret);
				}
			});
		}
		// 결과완료
		, finishNameAuth: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") self.close();
			
			var d = ret["결과값"];
			
			alert(d["메시지"]);
			if(d["응답코드"] == "1") this.openerControl.returnNameAuth(self, d["이름"]);
			self.close();
			
			//alert(d["응답코드"] + d["메시지"] + d["이름"]);
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});